import scrapy


class MovieSpider(scrapy.Spider):
    name = "movie"
    allowed_domains = ["movie.douban.com"]
    start_urls = ["https://movie.douban.com/chart"]

    def parse(self, response):
        # res = response.text
        # print(res)
        name = response.xpath('//*[@id="content"]/div/div[1]/div/div/table/tr/td[2]/div/a/text()')
        name_detail = response.xpath('//*[@id="content"]/div/div[1]/div/div/table/tr/td[2]/div/a/span/text()')
        new_name = [item.strip("\n ").strip("/").strip() for item in name.extract() if item.strip()]
        new_name_detail = name_detail.extract()
        # print(new_name)
        dic = {}
        for i in range(len(new_name)):
            a1 = new_name[i]
            a2 = new_name_detail[i]
            # print(a1, '/', a2)
            dic = {
                "movie_name": (a1 + '/' + a2)
            }
            yield dic
